【例子介绍】Socks5代理演示程序-DELPHI
【相关图片】
【源码结构】
unction connect_proxy(skt: TSocket; target: TSockAddr): boolean;
var
buf: array[0..1023] of byte;
re: integer;
begin
//preapre
buf[0] := SOCKS_VER5;
buf[1] := CMD_CONNECT;
buf[2] := RSV_DEFAULT;
buf[3] := ATYP_IPV4;
//copy data
copymemory(@buf[4], @target.sin_addr, 4);
copymemory(@buf[8], @target.sin_port, 2);
//communicate
re := send(skt, buf, 10, 0);
if re = -1 then
begin
result := false;
exit;
end;
re := recv(skt, buf, 1024, 0);
if re = -1 then
begin
result := false;
exit;
end;
if buf[1] <> REP_SUCCESS then
begin
result := false;
exit;
end;
result := true;
end;
评论